package com.gtp.mq.demo.spring.producer;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MyProducer {

	@Autowired
	private RabbitTemplate amqpTemplate;
	
	//发的时候指定队列
	public void test1(String msg){
		
		//最简单的
		amqpTemplate.convertAndSend("test_queue1", msg);
		
		//FanoutExchange -广播(routingKey无效)
		amqpTemplate.convertAndSend("FanoutExchange","",msg+"_f1");
		
		//DirectExchange -精确
		amqpTemplate.convertAndSend("DirectExchange","Direct_queue1",msg+"_d1");
		amqpTemplate.convertAndSend("DirectExchange","Direct_queue2",msg+"_d2");
		
		//topic-通配符
		amqpTemplate.convertAndSend("TopicExchange","Topic.k1.123",msg+"_k1");
		amqpTemplate.convertAndSend("TopicExchange","Topic.k2.456",msg+"_k2");
	}
}
